﻿
$(document).ready(function() {


//	document.body.ondrop = function (event) {
//		event.preventDefault();
//		event.stopPropagation();
//	}
//

	

	let countdownTimer;
	let countdownTime = 60;
	$('.tab').click(function() {
		var target = $(this).data('target');
		$('.tab').removeClass('active');
		$(this).addClass('active');
		$('.form-section').removeClass('active');
		$(target).addClass('active');
	});

	$('#loginPassword').click(function() {
		var username = $('#username').val();
		var password = $('#password').val();
		if (username === "") {
			showError("用户名或邮箱不能为空！");
		} else if (password === "") {
			showError("密码不能为空！");
		} else {
			alert("密码登录成功！");
		}
	});

	$('#sendSms').click(function() {
		var phone = $('#phone').val();
		if (phone === "" || !/^\d{11}$/.test(phone)) {
			showError("手机号不正确！");
		} else {
			startCountdown();
			alert("短信验证码已发送！");
		}
	});

	$('#loginPhone').click(function() {
		var phone = $('#phone').val();
		var imageCode = $('#imageCode').val();
		var smsCode = $('#smsCode').val();
		if (phone === "" || !/^\d{11}$/.test(phone)) {
			showError("手机号不正确！");
		} else if (imageCode === "") {
			showError("图片验证码不能为空！");
		} else if (smsCode === "") {
			showError("短信验证码不能为空！");
		} else {
			alert("手机登录成功！");
		}
	});
	function showError(message) {
		$('#errorMessage').text(message);
		$('#errorPopup').show();
	}

	function closePopup() {
		$('#errorPopup').hide();
	}

	function startCountdown() {
		$('#sendSms').prop('disabled', true);
		countdownTime = 60;
		countdownTimer = setInterval(function() {
			if (countdownTime <= 0) {
				clearInterval(countdownTimer);
				$('#sendSms').prop('disabled', false).text('发送验证码');
			} else {
				$('#sendSms').text(countdownTime + 's后重发');
				countdownTime--;
			}
		}, 1000);
	}

	function refreshCaptcha() {
		// 更新验证码图片的逻辑
		$('#imageCode').val(''); // 清空验证码输入框
		$('img[alt="验证码"]').attr('src', 'captcha.png?' + Math.random());
	}



	//分割线


	$(".vpn-box").click(function () {
		$(".tips-Popup").fadeIn(000);
	});
	$(".tips-Popup .bg").click(function () {
		$(".tips-Popup").fadeOut(000);
	});

	$(".Main-Body .Module-01 .tit-pub .r a.more").click(function () {
		$("#More-Popup").addClass("on");
	});
	$("#More-Popup .close-btn,#More-Popup .bg").click(function () {
		$("#More-Popup").removeClass("on");
	});
	// $("#scroll-bar ul li").click(function(){
	// 	$(this).siblings().removeClass("on");
	// 	$(this).addClass("on")
	// });
	//
	//
	// $('#scroll-bar ul li > a').on('click', function() {
	// 	if ( $(this).next().css('display') == "none" ) {
	// 		$('ul li .second-level').slideUp(300);
	// 		$(this).next('.second-level').slideDown(300);
	// 		$(this).parent('li').addClass('show').siblings('li').removeClass('show');
	// 	} else {
	// 		$(this).next('ul li .second-level').slideUp(300);
	// 		$('#scroll-bar ul li.show').removeClass('show');
	// 	}
	// });
	//
	// $("#Main-navigation .hide-btn").unbind("click").bind("click",function(){
	// 	if( !$(this).hasClass("on") ){
	// 		$(this).addClass("on");
	// 		$("#Main-navigation,.Main-Body").addClass("hide");
	// 		$(".Search-External-Box").addClass("width1");
	// 	} else {
	// 		$(this).removeClass("on");
	// 		$("#Main-navigation,.Main-Body").removeClass("hide");
	// 		$(".Search-External-Box").removeClass("width1");
	// 	}
	// });

	$("#Login-Account-Box .content .tab-box h2").click(function () {

		$(this).addClass("cur").siblings().removeClass('cur');
		$("#Login-Account-Box .content .login-box form").slideUp().eq($(this).index()).slideDown();
	});

	$(".Main-Right-Box .denglu span.cc,.header .right-box .login-btn").click(function () {
		$("#Login-Account-Box").addClass("ok");
	});
	$("#Login-Account-Box .off").click(function () {
		$("#Login-Account-Box").removeClass("ok");
	});


	$('.Main-Right-Box .Collection-box .list-box .add-btn').on('click', function () {
		var user_id = $("#user_id").val();
		if (user_id > 0) {
			$(".Main-Right-Box #add-Popup1").fadeIn(100);
		} else {
			$("#Login-Account-Box").addClass("ok");
		}

	});
	$('.Main-Right-Box .add-Popup h5').on('click', function () {
		$(".Main-Right-Box .add-Popup").fadeOut(100).removeClass("show");
	});


	$(".Main-Right-Box #add-Popup1 button").click(function () {

		var str = $(this).siblings("input[name='url']").val();
		var Expression = /http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/;
		var objExp = new RegExp(Expression);
		if (objExp.test(str) != true) {

			alert("网址格式不正确！请重新输入");
			return false;

		} else {
			var httpCode;
			var titCode;
			httpCode = $(this).siblings(".httpCode").val();
			titCode = $(this).siblings(".titCode").val();

			var httpCode2 = httpCode.replace(/.+[\.\/]([A-z]+\.[A-z]+)\/[^\/].+/, "$1");
			;//匹配bai指定URL的domain
			var reg = /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+$,\w]+@)?[A-Za-z0-9.-]+(:[0-9]+)?|(?:ww‌​w.|[-;:&=\+$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?‌​(?:[\w]*))?)/;

			//alert(httpCode2.substring(0,4));

			if (httpCode2.substring(0, 4) == "http") {
				var str = httpCode2.replace(reg, '');
				httpCode2 = httpCode2.replace(str, '');
				$(".Main-Right-Box .Collection-box .list-box ul#example1").append("<li><a href='" + httpCode + "'  target='_blank' class='a999' rel='nofollow'><div class='img-box'><img src='" + httpCode2 + "/favicon.ico' onerror=src='img/ico-lianjie.png' alt=' " + titCode + " '/></div><p title='" + titCode + "'>" + titCode + "</p><a href='javascript:;' class='iconfont modify-btn'>&#xe623;</a><i class='iconfont shanchu'>&#xe778;</i></a></li>");
				var logo = httpCode2 + '/favicon.ico'
			} else {
				httpCode2 = 'http://' + httpCode2;
				var str = httpCode2.replace(reg, '');
				httpCode2 = httpCode2.replace(str, '');
				$(".Main-Right-Box .Collection-box .list-box ul#example1").append("<li><a href='" + httpCode + "'  target='_blank' class='a999' rel='nofollow'><div class='img-box'><img src='" + httpCode2 + "/favicon.ico' onerror=src='img/ico-lianjie.png' alt=' " + titCode + " '/></div><p title='" + titCode + "'>" + titCode + "</p><a class='iconfont modify-btn'>&#xe623;</a><i class='iconfont shanchu'>&#xe778;</i></a></li>");
				var logo = httpCode2 + '/favicon.ico'
			}
			// if( httpCode2.substring(0,4) == "http"){
			//       $(".Main-Right-Box .Collection-box .list-box ul#example1").append("<li>< a href='" + httpCode + "'  target='_blank' class='a999' rel='nofollow'><div class='img-box'>< img src='" + httpCode2 + "/favicon.ico' onerror=src='img/ico-lianjie.png' alt=' " + titCode + " '/></div><p title='" + titCode + "'>" + titCode + "</p >< a href=' ' class='iconfont modify-btn'>&#xe623;</ a><i class='iconfont shanchu'>&#xe778;</i></ a></li>");
			// } else{
			//     $(".Main-Right-Box .Collection-box .list-box ul#example1").append("<li>< a href='" + httpCode + "'  target='_blank' class='a999' rel='nofollow'><div class='img-box'>< img src='http://" + httpCode2 + "/favicon.ico' onerror=src='img/ico-lianjie.png' alt=' " + titCode + " '/></div><p title='" + titCode + "'>" + titCode + "</p ><a class='iconfont modify-btn'>&#xe623;</ a><i class='iconfont shanchu'>&#xe778;</i></ a></li>");
			// } 
			return false;
			$.ajax({
				url: "",
				type: "post",
				data: {'foo': 'addwebsite', 'httpCode': httpCode, 'titCode': titCode, 'logo': logo},
				success: function (res) {

				},
			});

			httpCode = $(this).siblings(".httpCode").val("");
			titCode = $(this).siblings(".titCode").val("");
		}


	});

	$(".Main-Body .list-item-02 ul li .iconfont").click(function () {

		var that = this;
		var data_s = $(that).parent("li").attr("data-s");
		var f_a = $(that).siblings("a").attr("href");
		var f_ico = $(that).siblings("a").find("img").attr("src");
		var f_h2 = $(that).siblings("a").find("h2").html();
		var web_id = $(that).attr('id');
		$.ajax({
			url: "",
			type: "post",
			data: {'foo': 'collect', 'web_id': web_id},
			success: function (res) {
				if (res.status == 'notlogin') {
					$("#Login-Account-Box").addClass("ok");
				} else {
					if (!$(that).hasClass("off")) {

						$(that).addClass("off");


						var web_id = res.collect_id;
						$(".Main-Right-Box .Collection-box .list-box ul#example1").append("<li><a href='" + f_h2 + "'  target='_blank' class='a999' rel='nofollow'><div class='img-box'><img src=' " + f_ico + " ' alt=' " + f_ico + " '/></div><p title='" + f_h2 + "'>" + f_h2 + "</p></a><div class='off-btn iconfont' data-s = '" + data_s + "' onclick='delcollect(" + web_id + ")';>&#xe778;</div></li>");
					}
					layer.alert(res.msg);
				}


			},
		});


	});


	//粘贴链接后修改标题栏内容
	$(".Main-Right-Box .add-Popup").on('blur', '.httpCode', function () {
		var httpCode = $(this).val();
		$.ajax({
			url: "",
			type: "post",
			data: {'foo': 'getwebtitle', 'httpCode': httpCode},
			success: function (res) {
				$(".Main-Right-Box .add-Popup input.titCode").val(res);
			},
		});

	});

	/*拖拽*/
//	 new Sortable(example1, {
//		animation: 150,
//		ghostClass: 'blue-background-class',
//		 ghostClass: 'ghost',
//		 group: 'shared',
//		 scroll : 'true',
//		zIndex: 9999,
//		onEnd: function (/**Event*/evt) {
//			// 结束拖拽执行的事件
//		},
//	});
//	 new Sortable(example2, {
//		animation: 150,
//		 group: 'shared',
//		ghostClass: 'blue-background-class',
//		 ghostClass: 'ghost',
//		 scroll : 'true',
//		zIndex: 9999,
//		onEnd: function (/**Event*/evt) {
//			// 结束拖拽执行的事件
//		},
//	});
//	

	var nestedSortables = [].slice.call(document.querySelectorAll('.nested-sortable'));

	// Loop through each nested sortable element
	for (var i = 0; i < nestedSortables.length; i++) {
		new Sortable(nestedSortables[i], {
			group: 'nested',
			animation: 150,
			fallbackOnBody: true,
			swapThreshold: 0.65,
			// 结束拖拽
			onEnd: function (/**Event*/evt) {
				var itemEl = evt.item;  // dragged HTMLElement
				console.log(evt.oldIndex)
				$.ajax({
					url: "",
					type: "post",
					data: {'foo': 'websiteorder', 'oldIndex': evt.oldIndex, 'newIndex': evt.newIndex},
					success: function (res) {

					},
				});
			},
		});
	}
	;


	$(".Main-Right-Box .Collection-box .list-box > ul > li > a.folder-btn").on('click', function (event) {

		if ($(this).next().css('display') === "none") {
			/*$(".Main-Right-Box .Collection-box .list-box .two-d").hide();*/
			$(this).siblings(".two-d").show();
		} else {
			$(this).siblings(".two-d").hide();
		}
		event.stopPropagation();
	});

	$(".Main-Right-Box .Collection-box .list-box > ul > li > ul > li > a.folder-btn").on('click', function () {
		if ($(this).next().css('display') === "none") {
			/*$(this).parent().find(".two-d").hide();*/
			$(this).siblings(".two-d").show();
		} else {
			$(this).siblings(".two-d").hide();
		}
		event.stopPropagation();
	});


	var inputTit1 = $(".Main-Right-Box #add-Popup2 .titCode");
	var inputHttp1 = $(".Main-Right-Box #add-Popup2 .httpCode");


	$(".Main-Right-Box .Collection-box .list-box").on('click', 'ul li .modify-btn', function (event) {

		$(this).parent().siblings("li").removeClass("add9827");
		$(this).parent().addClass("add9827");

		var p_text = $(this).siblings("a.a999").find("p").text();
		var href = $(this).siblings("a.a999").attr('href');

		$(".Main-Right-Box #add-Popup2").addClass("show");
		inputTit1.val(p_text);
		inputHttp1.val(href);
		var web_id = $(this).attr('cid');
		$("#web_id").val(web_id);

	});

	$(".Main-Right-Box .Collection-box .list-box").on('click', 'ul li .off-btn', function (event) {
		var con_t = $(this).attr("data-s");
		$(this).removeClass("off");
		$(this).parent("li").remove();
		$(".Main-Body .list-item-02 ul li[data-s='" + con_t + "'] .iconfont").removeClass("off");
	});


	$(".Main-Right-Box #add-Popup2 button").on('click', function (event) {
		var web_id = $("#web_id").val();
		$(".Main-Right-Box #add-Popup2").removeClass("show");
		//alert("已修改");

		$(".add9827").find(".a999").attr("href", $(this).siblings(".httpCode").val());

		$(".add9827").find("p").text($(this).siblings(".titCode").val());
		$.ajax({
			url: "",
			type: "post",
			data: {
				'foo': 'editwebsite',
				'httpCode': $(this).siblings(".httpCode").val(),
				'titCode': $(this).siblings(".titCode").val(),
				'logo': $(this).siblings(".httpCode").val() + '/favicon.ico',
				'web_id': web_id
			},
			success: function (res) {

			},
		});
		//$(".add9827").find(".img-box img").attr('src',$(this).siblings(".httpCode").val() + 'favicon.ico');

		// var httpCode= $(this).siblings(".httpCode");
		// var httpCode2 = httpCode.replace(/.+[\.\/]([A-z]+\.[A-z]+)\/[^\/].+/,"$1");//匹配bai指定URL的domain

		//console.log(httpCode2)
		//alert(httpCode);	
		//alert(httpCode2.substring(0,4));
		// $(".add9827").find("p").html($(this).siblings(".titCode").val());
		// if( httpCode2.substring(0,4) == "http"){

		// 	$(".add9827").find(".img-box img").attr('src','' +httpCode2.val() + 'favicon.ico');

		// } else{

		// 	$(".add9827").find(".img-box img").attr('src','http://' +httpCode2.val() + 'favicon.ico');
		// }

	});


//	 $('.Main-Right-Box .Collection-box .list-box ul li > a').contextmenu(function() {
//        alert("修改内容");
//        return false;
//    });

	/*
	$( ".Main-Right-Box" ).resizable({
		handles: 'w',
		maxWidth: 360,
		minWidth: 196
	});*/


	/*
	$(".Main-Body .top-tools-tab ul li").on('click',function(){
		$(this).addClass("on").siblings().removeClass('on');
		tabScreen = $(this).data("screen");
		$(".Main-Body .wrap-tools-content ul li").hide();
		$(".Main-Body .wrap-tools-content ul li[data-screen='" + tabScreen + "']").show();
		
		if( tabScreen == "all" ){
		   $(".Main-Body .wrap-tools-content ul li").show();
		}
		
	});
	*/

	function getTop() {

		var top = $(document).scrollTop();
		if ($(document).scrollTop() > 90) {
			$(".Main-Body .top-tools-tab").addClass("cur");
		} else {
			$(".Main-Body .top-tools-tab").removeClass("cur");
		}
		setTimeout(getTop);
	}

	getTop();


	/**/
	$(".Main-Body .wrap-tools-content ul li .r-t span").on('click', function () {

		var class_y = $(this).parent().parent().hasClass("on");
		if (!class_y) {

			href = $(this).parent().siblings(".img-box").find("a").attr("href");

			dataName = $(this).parent().parent().data("name");

			img = $(this).parent().siblings(".img-box").find("img").attr("src");

			tit = $(this).siblings("h2").find("a").text();

			introduce = $(this).parent().siblings(".a-bd").find("p").text();

			$(this).parent().parent().addClass("on");

			$(".tool-collection ul").append("<li data-name='" + dataName + "'><a href='" + href + "'><img src='" + img + "' alt=''><h2>" + tit + "</h2><p>" + introduce + "</p></a><a href='javascript:;' class='iconfont'>&#xe778;</a></li>");
		} else {
			alert("已添加");
		}


	});


	$(".tool-collection ul").on('click', 'li .iconfont', function () {
		dataName = $(this).parent().attr('data-name');

		$(".Main-Body .wrap-tools-content ul li[data-name='" + dataName + "']").removeClass("on");
		$(this).parent().remove();
	});


	/*首页搜索引擎*/
	$(".Search-External-Box .tab .btn-s").click(function () {
		$(this).addClass("on").siblings().removeClass("on");
		$(".Search-External-Box .search-Engine .box-s").eq($(".Search-External-Box .tab .btn-s").index(this)).addClass("active").siblings().removeClass('active');
	});


});




















